import Vue from "vue";
import Router from "vue-router";
Vue.use(Router);
import Layout from "@/layout";

export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true
  },
  {
    path: "/datascreen",
    component: () => import("@/views/datascreen/index"),
    hidden: true
  },
  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true
  },

  {
    path: "/",
    component: Layout,
    redirect: "/datascreen",
    children: [
      {
        path: "datascreen",
        name: "datascreen",
        component: () => import("@/views/datascreen/index"),
        meta: { title: "主页", icon: "dashboard" }
      }
    ]
  },
  {
    path: "/branchManagement",
    component: Layout,
    children: [
      {
        path: "/branchManagement",
        component: () => import("@/views/branchManagement/index"),
        meta: { title: "分局管理", icon: "branchManagement" }
      }
    ]
  },
  {
    path: "/userManagement",
    component: Layout,
    children: [
      {
        path: "/userManagement",
        component: () => import("@/views/userManagement/index"),
        meta: { title: "用户管理", icon: "user" }
      }
    ]
  },
  {
    path: "/stationsManagement",
    component: Layout,
    children: [
      {
        name: "/stationsManagement",
        path: "/stationsManagement",
        component: () => import("@/views/stationsManagement/index"),
        meta: { title: "加油站管理", icon: "station" }
      },
      {
        path: "/stationsManagement/guns",
        name: "/guns",
        component: () => import("@/views/stationsManagement/guns"),
        hidden: true
      },
      {
        path: "/stationsManagement/SalesStatistics",
        name: "/SalesStatistics",
        component: () => import("@/views/stationsManagement/SalesStatistics"),
        hidden: true
      }
    ]
  },
  {
    path: "/divisionStatistics",
    component: Layout,
    children: [
      {
        name: "/divisionStatistics",
        path: "/divisionStatistics",
        component: () => import("@/views/divisionStatistics/index"),
        meta: { title: "辖区分局统计", icon: "division" }
      }
    ]
  },
  {
    path: "/recordsQuery",
    component: Layout,
    children: [
      {
        path: "/recordsQuery",
        component: () => import("@/views/recordsQuery/index"),
        meta: { title: "加油记录查询", icon: "form" }
      }
    ]
  },
  {
    path: "/DeviceStatus",
    component: Layout,
    children: [
      {
        path: "/DeviceStatus",
        component: () => import("@/views/deviceStatus/index"),
        meta: { title: "设备状态查询", icon: "DeviceStatus" }
      }
    ]
  },
  {
    path: "/warningLevel",
    component: Layout,
    children: [
      {
        path: "/warningLevel",
        component: () => import("@/views/warningLevel/index"),
        meta: { title: "警告等级设置", icon: "waring_level" }
      }
    ]
  },
  {
    path: "/warningList",
    component: Layout,
    children: [
      {
        path: "/warningList",
        component: () => import("@/views/warningList/index"),
        meta: { title: "设备警告列表", icon: "waring_list" }
      }
    ]
  },
  { path: "*", redirect: "/404", hidden: true }
];

const createRouter = () =>
  new Router({
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  });

const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
